% Chakram is a subproject of Hexena - Haskell Executable Analyser
% License:			GPL-3
% Maintainer:		Montez Fitzpatrick
% Stability:		Experimental
% Portability:		GHC
% Module:			Hexena.Data.PECOFF

This will generalize the base structure of the Portable Executable ("PE") and Common
Object File Formats ("COFF") specially as used by Microsoft Windows.  Naming conventions should
be relatively easy to decipher, perhaps confusingly though executables will be known as "Image" and
object files, including DLLs will be generalized as "Obj" unless specified otherwise.

it is important to note that the PE/COFF specification is more strict than the practical implementation
performed by the loader.  Every attempt is made to try to account for those known quirks when 
processing the PE/COFF file.  Please contact the library maintainer if there are errors or omissions during the parsing of a PE/COFF file.

Note:

@RVA@ ("Relative Virtual Address") notates the actually address of an item after it has been loaded into
memory. The RVA may not point to the same address as the layout on disk.  RVAs are calculate from the base of the image file.  RVAs may be less helpful when it comes to Obj files.

@VA@ ("Virtual Address") is everything that is the RVA.  It is less useful in our situation since this library will analyze statically from disk.  Windows assigned a virtual address once the PECOFF file is loaded, except with RVA the base address is subtracted so the base starts at (0x00).  The VA will not subtract that number from the base.

@Section@ is the PE bread and butter, as it is where the code and data live.  The table-of-contents for the section is usually referred to as the Section Table or Section Header.  While the individual Sections are usually referred to as the Section Pages or Section Data.

\begin{code}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeOperators #-}
-- | ** Base PE COFF Type **
module Hexena.Data.PECOFF 
	(
	-- * Data Structures
	  PE(..)
	) where

import qualified Data.ByteString.Lazy as L

import Data.Label -- needs 'fclabels' package

import Hexena.Data.MzHeader (MzHeader(..))
import Hexena.Data.DOSStub (DOSStub(..))
import Hexena.Data.PEHeader (PEHeader(..))
import Hexena.Data.SectionHeader(SectionHeader(..))
import Hexena.Data.ParseRawSections (RawSections(..)) -- Temp


-- | Container for the PE data type.  Every variation supported must be accounted for
--   to fit into this type.
data PE = PE
	{ _mzHeader :: MzHeader
	, _dosStub :: DOSStub
	, _peHeader :: PEHeader
	, _sectionHeader :: SectionHeader
	, _rawSections :: RawSections -- Temp
	, _rest :: L.ByteString -- Temp
	} deriving (Show, Eq, Ord)

-- | Automagically derive getters and setters for PE data type.  
mkLabel ''PE

\end{code}
